namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class IndicatorPsychologicalLine : BaseIndicator
    {
        private LineShape tlsPsy;

        public IndicatorPsychologicalLine()
        {
            base.IndType = IndicatorType.PSY;
            base.IndName = "PSY";
            base.IndDesc = "心理线";
            base.IndPeriod.Add(new IndicatorPeriod(0, "N", 12.0));
            base.SourceDic["Close"] = "";
            base.fields = new string[] { "PSY" };
        }

        public override bool Contains(object obj)
        {
            return (obj == this.tlsPsy);
        }

        public override double[] Get(int r)
        {
            int num = r - (((int) base.IndPeriod[0].ParamValue) - 1);
            if (num < 0)
            {
                num = 0;
            }
            int num2 = 0;
            for (int i = r; i >= num; i--)
            {
                double num4 = Convert.ToDouble(base.Crab.DataSource.Rows[i][base.SourceDic["Close"]]);
                double num5 = 0.0;
                if (i > 0)
                {
                    num5 = Convert.ToDouble(base.Crab.DataSource.Rows[i - 1][base.SourceDic["Close"]]);
                }
                if (num4 > num5)
                {
                    num2++;
                }
            }
            double num6 = (((double) num2) / base.IndPeriod[0].ParamValue) * 100.0;
            return new double[] { num6 };
        }

        public override List<BaseShape> GetShapeList()
        {
            return new List<BaseShape> { this.tlsPsy };
        }

        public override void Remove()
        {
            base.Crab.DeleteShape(this.TlsPsy);
        }

        public override bool Set(int r, string target)
        {
            try
            {
                DataRow row = base.Crab.DataSource.Rows[r];
                foreach (string str in base.SourceDic.Values)
                {
                    if ((str == target) || (target == null))
                    {
                        foreach (string str2 in base.SourceDic.Values)
                        {
                            if (row[str2] is DBNull)
                            {
                                return false;
                            }
                        }
                        double num = this.Get(r)[0];
                        base.Crab.SetValue(this.TlsPsy.Name, num, r);
                        return true;
                    }
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        public override void SetParam(string[] fields, string[] source, double[] periods, int panelID)
        {
            this.TlsPsy = base.Crab.AddLine(fields[0], panelID);
            base.SourceDic["Close"] = source[0];
            base.IndPeriod[0].ParamValue = periods[0];
        }

        public LineShape TlsPsy
        {
            get
            {
                return this.tlsPsy;
            }
            set
            {
                this.tlsPsy = value;
            }
        }
    }
}

